define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'studentinfo/index' + location.search,
                    add_url: 'studentinfo/add',
                    edit_url: 'studentinfo/edit',
                    del_url: 'studentinfo/del',
                    multi_url: 'studentinfo/multi',
                    import_url: 'studentinfo/import',
                    table: 'studentinfo',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'updatetime',
                //showExport: false,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'sex', title: __('Sex'), operate: 'LIKE'},
                        {field: 'tel', title: __('Tel'), operate: 'LIKE'},
                        {field: 'idno', title: __('Idno'), operate: 'LIKE'},
                        {field: 'grade', title: __('Grade'), operate: 'LIKE'},
                        {field: 'xuezhi', title: __('Xuezhi'), operate: 'LIKE'},
                        {field: 'department', title: __('Department'), operate: 'LIKE'},
                        {field: 'classname', title: __('Classname'), operate: 'LIKE'},
                        {field: 'score', title: __('Score'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        {field: 'year', title: __('Year'), operate: 'LIKE'},
                        {field: 'payall', title: __('Payall'), operate:'BETWEEN'},
                        {field: 'pay1', title: __('Pay1'), operate:'BETWEEN'},
                        {field: 'pay2', title: __('Pay2'), operate:'BETWEEN'},
                        { field: 'pay9', title: __('Pay9'), operate: 'BETWEEN' },
                        { field: 'pay3', title: __('Pay3'), operate: 'BETWEEN' },
                        { field: 'pay8', title: __('Pay8'), operate: 'BETWEEN' },
                        {field: 'pay4', title: __('Pay4'), operate:'BETWEEN'},
                        {field: 'pay6', title: __('Pay6'), operate:'BETWEEN'},
                        {field: 'pay7', title: __('Pay7'), operate:'BETWEEN'},
                        {field: 'pay5', title: __('Pay5'), operate:'BETWEEN'},
                        {field: 'mete', title: __('Mete'), operate: 'LIKE'},
                        {field: 'school', title: __('School'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'edit',
                                    icon: 'fa fa-pencil',
                                    title: __('Edit'),
                                    text: '编辑',//显示的字
                                    extend: 'data-toggle="tooltip"',
                                    classname: 'btn btn-xs btn-success btn-editone',
                                    visible: function (row) {
                                        return row.status === "0";
                                    }
                                },
                                {
                                    name: 'del',
                                    icon: 'fa fa-trash',
                                    title: __('Del'),
                                    text: '删除',//显示的字
                                    extend: 'data-toggle="tooltip"',
                                    classname: 'btn btn-xs btn-danger btn-delone',
                                    visible: function (row) {
                                        return row.status === "0";
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            $("input[name='row[idno]']").on('blur',function(){
                var idno = $("input[name='row[idno]']").val();
                // alert(jQuery("#tel").val());
                $.get("http://gongshang.runwhale.com/api/demo/qidno?idno="+idno,function(data){
                    var obj =eval(data);

                    if (obj.code==0){
                        //没有学生信息
                    }else{
                        var count =obj.data.listcount;
                        var idstr =obj.data.listidstr;
                        alert("已存在 "+count+" 条记录，"+idstr+"若状态都是已缴齐请继续添加，若存在未交的记录请前往那条记录修改金额，不需要重新添加。若想添加多条记录可继续添加！");
                    }
                });
                if(idno.length==18){
                    const genderCode = idno.charAt(16);
                    if (genderCode % 2 === 0) {
                        document.getElementById('row[sex]-女').checked = true;
                    } else {
                        document.getElementById('row[sex]-男').checked = true;
                    }
                }
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay1]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });
            $("input[name='row[pay2]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });
            $("input[name='row[pay3]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;
                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;

                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay4]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay5]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay6]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay7]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay8]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay9]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });


        },
        edit: function () {
            Controller.api.bindevent();



            var pay1 = $("input[name='row[pay1]']").val();
            var pay2 = $("input[name='row[pay2]']").val();
            var pay3 = $("input[name='row[pay3]']").val();
            var pay4 = $("input[name='row[pay4]']").val();
            var pay5 = $("input[name='row[pay5]']").val();
            var pay6 = $("input[name='row[pay6]']").val();
            var pay7 = $("input[name='row[pay7]']").val();
            var pay8 = $("input[name='row[pay8]']").val();
            var pay9 = $("input[name='row[pay9]']").val();

            var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;
            //其他汇总
            $("input[name='payotherall").val(all);




            $("input[name='row[pay1]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });
            $("input[name='row[pay2]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });
            $("input[name='row[pay3]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100 )/100;
                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;

                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay4]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay5]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay6]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay7]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay8]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });

            $("input[name='row[pay9]']").on('blur',function(){
                var pay1 = $("input[name='row[pay1]']").val();
                var pay2 = $("input[name='row[pay2]']").val();
                var pay3 = $("input[name='row[pay3]']").val();
                var pay4 = $("input[name='row[pay4]']").val();
                var pay5 = $("input[name='row[pay5]']").val();
                var pay6 = $("input[name='row[pay6]']").val();
                var pay7 = $("input[name='row[pay7]']").val();
                var pay8 = $("input[name='row[pay8]']").val();
                var pay9 = $("input[name='row[pay9]']").val();

                var all=(pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100)/100;

                //其他汇总
                $("input[name='payotherall").val(all);
                //document.getElementById("payotherall").innerHTML=all;


                var all1=(pay1*100+pay2*100+pay3*100+pay4*100+pay5*100+pay6*100+pay7*100+pay8*100+pay9*100)/100;

                $("input[name='row[payall]']").val(all1);
                //下面就可以修改 另一个文本框的值了
            });
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});